﻿namespace UnityEditor
{
    using System;
    using System.Collections;
    using UnityEditorInternal;
    using UnityEngine;

    internal class ProfilerWindow : EditorWindow, IProfilerWindowController
    {
        private const int kFirst = -999999;
        private const int kLast = 0xf423f;
        internal const string kPrefCharts = "ProfilerChart";
        private const string kProfilerColumnSettings = "VisibleProfilerColumnsV2";
        private const string kProfilerDetailColumnSettings = "VisibleProfilerDetailColumns";
        private const string kProfilerGPUColumnSettings = "VisibleProfilerGPUColumns";
        private const string kProfilerGPUDetailColumnSettings = "VisibleProfilerGPUDetailColumns";
        private const string kProfilerVisibleGraphsSettings = "VisibleProfilerGraphs";
        private const float kRowHeight = 16f;
        private float m_ChartMaxClamp;
        private float[] m_ChartOldMax;
        private ProfilerChart[] m_Charts;
        private int[] m_ConnectionGuids;
        private ProfilerHierarchyGUI m_CPUDetailHierarchyGUI;
        private ProfilerHierarchyGUI m_CPUHierarchyGUI;
        private ProfilerArea m_CurrentArea;
        private int m_CurrentFrame;
        private ProfilerHierarchyGUI m_GPUDetailHierarchyGUI;
        private ProfilerHierarchyGUI m_GPUHierarchyGUI;
        private Vector2 m_GraphPos;
        private bool m_HasProfilerLicense;
        private int m_LastFrameFromTick;
        private Vector2[] m_PaneScroll;
        private int m_PrevLastFrame;
        private static ArrayList m_ProfilerWindows = new ArrayList();
        [SerializeField]
        private bool m_Recording;
        private SplitterState m_VertSplit;
        private SplitterState m_ViewSplit;
        private ProfilerViewType m_ViewType;
        private static Styles ms_Styles;

        public ProfilerWindow()
        {
            float[] relativeSizes = new float[] { 50f, 50f };
            int[] minSizes = new int[] { 50, 50 };
            this.m_VertSplit = new SplitterState(relativeSizes, minSizes, null);
            float[] singleArray2 = new float[] { 70f, 30f };
            int[] numArray2 = new int[] { 450, 50 };
            this.m_ViewSplit = new SplitterState(singleArray2, numArray2, null);
            this.m_Recording = true;
            this.m_GraphPos = Vector2.zero;
            this.m_PaneScroll = new Vector2[6];
            this.m_CurrentFrame = -1;
            this.m_LastFrameFromTick = -1;
            this.m_PrevLastFrame = -1;
            this.m_ChartOldMax = new float[] { -1f, -1f };
            this.m_ChartMaxClamp = 70000f;
            m_ProfilerWindows.Add(this);
            this.m_HasProfilerLicense = InternalEditorUtility.HasPro();
            int len = ProfilerDriver.maxHistoryLength - 1;
            this.m_Charts = new ProfilerChart[6];
            Color[] colorArray = new Color[] { new Color(0.4831376f, 0.6211768f, 0.0219608f, 1f), new Color(0.2070592f, 0.5333336f, 0.6556864f, 1f), new Color(0.8f, 0.4423528f, 0f, 1f), new Color(0.4486272f, 0.4078432f, 0.050196f, 1f), new Color(0.7749016f, 0.6368624f, 0.0250984f, 1f), new Color(0.5333336f, 0.16f, 0.0282352f, 1f), new Color(0.3827448f, 0.2886272f, 0.5239216f, 1f), new Color(0.279216f, 0.4078432f, 0.5835296f, 1f) };
            for (ProfilerArea area = ProfilerArea.CPU; area < ProfilerArea.AreaCount; area += 1)
            {
                float dataScale = 1f;
                Chart.ChartType line = Chart.ChartType.Line;
                string[] graphStatisticsPropertiesForArea = ProfilerDriver.GetGraphStatisticsPropertiesForArea(area);
                int length = graphStatisticsPropertiesForArea.Length;
                switch (area)
                {
                    case ProfilerArea.GPU:
                    case ProfilerArea.CPU:
                        line = Chart.ChartType.StackedFill;
                        dataScale = 0.001f;
                        break;
                }
                ProfilerChart chart = new ProfilerChart(area, line, dataScale, length);
                for (int i = 0; i < length; i++)
                {
                    chart.m_Series[i] = new ChartSeries(graphStatisticsPropertiesForArea[i], len, colorArray[i]);
                }
                this.m_Charts[(int) area] = chart;
            }
            this.UpdateCharts();
            this.BuildColumns();
            foreach (ProfilerChart chart2 in this.m_Charts)
            {
                chart2.LoadAndBindSettings();
            }
        }

        private void AddAreaClick(object userData, string[] options, int selected)
        {
            this.m_Charts[selected].m_Active = true;
            EditorPrefs.SetBool("ProfilerChart" + ((ProfilerArea) selected), true);
        }

        private void Awake()
        {
            if (Profiler.supported)
            {
                Profiler.enabled = this.m_Recording;
            }
        }

        private void BuildColumns()
        {
            ProfilerColumn[] columnArray1 = new ProfilerColumn[7];
            columnArray1[1] = ProfilerColumn.TotalPercent;
            columnArray1[2] = ProfilerColumn.SelfPercent;
            columnArray1[3] = ProfilerColumn.Calls;
            columnArray1[4] = ProfilerColumn.GCMemory;
            columnArray1[5] = ProfilerColumn.TotalTime;
            columnArray1[6] = ProfilerColumn.SelfTime;
            ProfilerColumn[] columnsToShow = columnArray1;
            ProfilerColumn[] columns = new ProfilerColumn[] { ProfilerColumn.ObjectName, ProfilerColumn.TotalPercent, ProfilerColumn.SelfPercent, ProfilerColumn.Calls, ProfilerColumn.GCMemory, ProfilerColumn.TotalTime, ProfilerColumn.SelfTime };
            this.m_CPUHierarchyGUI = new ProfilerHierarchyGUI(this, "VisibleProfilerColumnsV2", columnsToShow, ProfilerColumnNames(columnsToShow), false, ProfilerColumn.TotalTime);
            string text = EditorGUIUtility.TextContent("ProfilerColumn.DetailViewObject").text;
            string[] columnNames = ProfilerColumnNames(columns);
            columnNames[0] = text;
            this.m_CPUDetailHierarchyGUI = new ProfilerHierarchyGUI(this, "VisibleProfilerDetailColumns", columns, columnNames, true, ProfilerColumn.TotalTime);
            ProfilerColumn[] columnArray6 = new ProfilerColumn[4];
            columnArray6[1] = ProfilerColumn.TotalGPUPercent;
            columnArray6[2] = ProfilerColumn.DrawCalls;
            columnArray6[3] = ProfilerColumn.TotalGPUTime;
            ProfilerColumn[] columnArray3 = columnArray6;
            ProfilerColumn[] columnArray4 = new ProfilerColumn[] { ProfilerColumn.ObjectName, ProfilerColumn.TotalGPUPercent, ProfilerColumn.DrawCalls, ProfilerColumn.TotalGPUTime };
            this.m_GPUHierarchyGUI = new ProfilerHierarchyGUI(this, "VisibleProfilerGPUColumns", columnArray3, ProfilerColumnNames(columnArray3), false, ProfilerColumn.TotalGPUTime);
            columnNames = ProfilerColumnNames(columnArray4);
            columnNames[0] = text;
            this.m_GPUDetailHierarchyGUI = new ProfilerHierarchyGUI(this, "VisibleProfilerGPUDetailColumns", columnArray4, columnNames, true, ProfilerColumn.TotalGPUTime);
        }

        private static bool CheckFrameData(ProfilerProperty property)
        {
            if (!property.frameDataReady)
            {
                GUILayout.Label(ms_Styles.noData, ms_Styles.background, new GUILayoutOption[0]);
                return false;
            }
            return true;
        }

        public void ClearSelectedPropertyPath()
        {
            if (ProfilerDriver.selectedPropertyPath != string.Empty)
            {
                this.m_CPUHierarchyGUI.selectedIndex = -1;
                ProfilerDriver.selectedPropertyPath = string.Empty;
                this.UpdateCharts();
            }
        }

        public ProfilerProperty CreateProperty(bool details)
        {
            ProfilerProperty property = new ProfilerProperty();
            ProfilerColumn profilerSortColumn = (this.m_CurrentArea != ProfilerArea.CPU) ? (!details ? this.m_GPUHierarchyGUI.sortType : this.m_GPUDetailHierarchyGUI.sortType) : (!details ? this.m_CPUHierarchyGUI.sortType : this.m_CPUDetailHierarchyGUI.sortType);
            property.SetRoot(this.GetActiveVisibleFrameIndex(), profilerSortColumn, this.m_ViewType);
            property.onlyShowGPUSamples = this.m_CurrentArea == ProfilerArea.GPU;
            return property;
        }

        private void DrawCPUOrRenderingPane(ProfilerHierarchyGUI mainPane, ProfilerHierarchyGUI detailPane, SplitterState splitter)
        {
            ProfilerProperty property = this.CreateProperty(false);
            this.DrawCPUOrRenderingToolbar(property);
            if (!CheckFrameData(property))
            {
                property.Cleanup();
            }
            else
            {
                SplitterGUILayout.BeginHorizontalSplit(splitter, new GUILayoutOption[0]);
                GUILayout.BeginVertical(new GUILayoutOption[0]);
                mainPane.DoGUI(property);
                property.Cleanup();
                GUILayout.EndVertical();
                GUILayout.BeginVertical(new GUILayoutOption[0]);
                ProfilerProperty property2 = this.CreateProperty(true);
                ProfilerProperty detailedProperty = mainPane.GetDetailedProperty(property2);
                property2.Cleanup();
                if (detailedProperty != null)
                {
                    detailPane.DoGUI(detailedProperty);
                    detailedProperty.Cleanup();
                }
                else
                {
                    DrawEmptyCPUOrRenderingDetailPane();
                }
                GUILayout.EndVertical();
                SplitterGUILayout.EndHorizontalSplit();
            }
        }

        private void DrawCPUOrRenderingToolbar(ProfilerProperty property)
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, new GUILayoutOption[0]);
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(100f) };
            this.m_ViewType = (ProfilerViewType) EditorGUILayout.EnumPopup(this.m_ViewType, EditorStyles.toolbarDropDown, options);
            GUILayout.FlexibleSpace();
            GUILayout.Label(string.Format("CPU:{0}ms   GPU:{1}ms", property.frameTime, property.frameGpuTime), EditorStyles.miniLabel, new GUILayoutOption[0]);
            EditorGUILayout.EndHorizontal();
        }

        private static void DrawEmptyCPUOrRenderingDetailPane()
        {
            GUILayout.Box(string.Empty, ms_Styles.header, new GUILayoutOption[0]);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.FlexibleSpace();
            GUILayout.Label("Select Line for per-object breakdown", EditorStyles.wordWrappedLabel, new GUILayoutOption[0]);
            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }

        private void DrawMainToolbar()
        {
            GUILayout.BeginHorizontal(EditorStyles.toolbar, new GUILayoutOption[0]);
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(120f) };
            Rect position = GUILayoutUtility.GetRect(ms_Styles.addArea, EditorStyles.toolbarDropDown, options);
            if (EditorGUI.ButtonMouseDown(position, ms_Styles.addArea, FocusType.Native, EditorStyles.toolbarDropDown))
            {
                int length = this.m_Charts.Length;
                string[] strArray = new string[length];
                bool[] enabled = new bool[length];
                for (int i = 0; i < length; i++)
                {
                    strArray[i] = ((ProfilerArea) i).ToString();
                    enabled[i] = !this.m_Charts[i].m_Active;
                }
                EditorUtility.DisplayCustomMenu(position, strArray, enabled, null, new EditorUtility.SelectMenuItemFunction(this.AddAreaClick), null);
            }
            GUILayout.FlexibleSpace();
            this.m_Recording = GUILayout.Toggle(this.m_Recording, ms_Styles.profilerRecord, EditorStyles.toolbarButton, new GUILayoutOption[0]);
            Profiler.enabled = this.m_Recording;
            SetProfileDeepScripts(GUILayout.Toggle(ProfilerDriver.deepProfiling, ms_Styles.deepProfile, EditorStyles.toolbarButton, new GUILayoutOption[0]));
            ProfilerDriver.profileEditor = GUILayout.Toggle(ProfilerDriver.profileEditor, ms_Styles.profileEditor, EditorStyles.toolbarButton, new GUILayoutOption[0]);
            GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.Width(100f) };
            Rect rect2 = GUILayoutUtility.GetRect(ms_Styles.currentProfiler, EditorStyles.toolbarDropDown, optionArray2);
            if (EditorGUI.ButtonMouseDown(rect2, ms_Styles.currentProfiler, FocusType.Native, EditorStyles.toolbarDropDown))
            {
                int connectedProfiler = ProfilerDriver.connectedProfiler;
                this.m_ConnectionGuids = ProfilerDriver.GetAvailableProfilers();
                int num4 = this.m_ConnectionGuids.Length;
                int[] selected = new int[1];
                bool[] flagArray2 = new bool[num4];
                string[] strArray2 = new string[num4];
                for (int j = 0; j < num4; j++)
                {
                    int guid = this.m_ConnectionGuids[j];
                    bool flag = ProfilerDriver.IsIdentifierConnectable(guid);
                    flagArray2[j] = flag;
                    string connectionIdentifier = ProfilerDriver.GetConnectionIdentifier(guid);
                    if (!flag)
                    {
                        connectionIdentifier = connectionIdentifier + " (Version mismatch)";
                    }
                    strArray2[j] = connectionIdentifier;
                    if (guid == connectedProfiler)
                    {
                        selected[0] = j;
                    }
                }
                EditorUtility.DisplayCustomMenu(rect2, strArray2, flagArray2, selected, new EditorUtility.SelectMenuItemFunction(this.SelectProfilerClick), null);
            }
            if (GUILayout.Button(ms_Styles.clearData, EditorStyles.toolbarButton, new GUILayoutOption[0]))
            {
                ProfilerDriver.ClearAllFrames();
            }
            GUILayout.Space(5f);
            GUILayout.FlexibleSpace();
            this.FrameNavigationControls();
            GUILayout.EndHorizontal();
        }

        private static void DrawOtherToolbar(ProfilerProperty property)
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, new GUILayoutOption[0]);
            GUILayout.FlexibleSpace();
            GUILayout.Label(string.Format("CPU:{0}ms   GPU:{1}ms", property.frameTime, property.frameGpuTime), EditorStyles.miniLabel, new GUILayoutOption[0]);
            EditorGUILayout.EndHorizontal();
        }

        private void DrawPane(ProfilerArea area)
        {
            ProfilerProperty property = this.CreateProperty(false);
            DrawOtherToolbar(property);
            bool flag = CheckFrameData(property);
            property.Cleanup();
            if (flag)
            {
                this.m_PaneScroll[(int) area] = GUILayout.BeginScrollView(this.m_PaneScroll[(int) area], ms_Styles.background);
                GUILayout.Label(ProfilerDriver.GetOverviewText(area, this.GetActiveVisibleFrameIndex()), EditorStyles.wordWrappedLabel, new GUILayoutOption[0]);
                GUILayout.EndScrollView();
            }
        }

        private void FrameNavigationControls()
        {
            if (this.m_CurrentFrame > ProfilerDriver.lastFrameIndex)
            {
                this.SetCurrentFrameDontPause(ProfilerDriver.lastFrameIndex);
            }
            GUILayout.Label(ms_Styles.frame, EditorStyles.miniLabel, new GUILayoutOption[0]);
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(100f) };
            GUILayout.Label("   " + this.PickFrameLabel(), EditorStyles.miniLabel, options);
            GUI.enabled = ProfilerDriver.GetPreviousFrameIndex(this.m_CurrentFrame) != -1;
            if (GUILayout.Button(ms_Styles.prevFrame, EditorStyles.toolbarButton, new GUILayoutOption[0]))
            {
                this.PrevFrame();
            }
            GUI.enabled = ProfilerDriver.GetNextFrameIndex(this.m_CurrentFrame) != -1;
            if (GUILayout.Button(ms_Styles.nextFrame, EditorStyles.toolbarButton, new GUILayoutOption[0]))
            {
                this.NextFrame();
            }
            GUI.enabled = true;
            GUILayout.Space(10f);
            if (GUILayout.Button(ms_Styles.currentFrame, EditorStyles.toolbarButton, new GUILayoutOption[0]))
            {
                this.SetCurrentFrame(-1);
                this.m_LastFrameFromTick = ProfilerDriver.lastFrameIndex;
            }
        }

        private int GetActiveVisibleFrameIndex()
        {
            return ((this.m_CurrentFrame != -1) ? this.m_CurrentFrame : this.m_LastFrameFromTick);
        }

        private void NextFrame()
        {
            int nextFrameIndex = ProfilerDriver.GetNextFrameIndex(this.m_CurrentFrame);
            if (nextFrameIndex != -1)
            {
                this.SetCurrentFrame(nextFrameIndex);
            }
        }

        private void OnDestroy()
        {
            if (Profiler.supported)
            {
                Profiler.enabled = false;
            }
        }

        private void OnDisable()
        {
            m_ProfilerWindows.Remove(this);
        }

        private void OnFocus()
        {
            if (Profiler.supported)
            {
                Profiler.enabled = this.m_Recording;
            }
        }

        private void OnGUI()
        {
            if (ms_Styles == null)
            {
                ms_Styles = new Styles();
            }
            if (!this.m_HasProfilerLicense)
            {
                GUILayout.Label(ms_Styles.noLicense, EditorStyles.largeLabel, new GUILayoutOption[0]);
            }
            else
            {
                this.DrawMainToolbar();
                SplitterGUILayout.BeginVerticalSplit(this.m_VertSplit, new GUILayoutOption[0]);
                this.m_GraphPos = EditorGUILayout.BeginScrollView(this.m_GraphPos, ms_Styles.profilerGraphBackground);
                if (this.m_PrevLastFrame != ProfilerDriver.lastFrameIndex)
                {
                    this.UpdateCharts();
                    this.m_PrevLastFrame = ProfilerDriver.lastFrameIndex;
                }
                int currentFrame = this.m_CurrentFrame;
                Chart.ChartAction[] actionArray = new Chart.ChartAction[this.m_Charts.Length];
                for (int i = 0; i < this.m_Charts.Length; i++)
                {
                    ProfilerChart chart = this.m_Charts[i];
                    if (chart.m_Active)
                    {
                        currentFrame = chart.DoChartGUI(currentFrame, this.m_CurrentArea, out actionArray[i]);
                    }
                }
                bool flag = false;
                if (currentFrame != this.m_CurrentFrame)
                {
                    this.SetCurrentFrame(currentFrame);
                    flag = true;
                }
                for (int j = 0; j < this.m_Charts.Length; j++)
                {
                    ProfilerChart chart2 = this.m_Charts[j];
                    if (chart2.m_Active)
                    {
                        if (actionArray[j] == Chart.ChartAction.Closed)
                        {
                            if (this.m_CurrentArea == j)
                            {
                                this.m_CurrentArea = ProfilerArea.CPU;
                            }
                            chart2.m_Active = false;
                            EditorPrefs.SetBool("ProfilerChart" + ((ProfilerArea) j), false);
                        }
                        else if (actionArray[j] == Chart.ChartAction.Activated)
                        {
                            this.m_CurrentArea = (ProfilerArea) j;
                            if ((this.m_CurrentArea != ProfilerArea.CPU) && (this.m_CPUHierarchyGUI.selectedIndex != -1))
                            {
                                this.ClearSelectedPropertyPath();
                            }
                            flag = true;
                        }
                    }
                }
                if (flag)
                {
                    base.Repaint();
                    GUIUtility.ExitGUI();
                }
                GUILayout.EndScrollView();
                GUILayout.BeginVertical(new GUILayoutOption[0]);
                if (this.m_CurrentArea == ProfilerArea.CPU)
                {
                    this.DrawCPUOrRenderingPane(this.m_CPUHierarchyGUI, this.m_CPUDetailHierarchyGUI, this.m_ViewSplit);
                }
                else if (this.m_CurrentArea == ProfilerArea.GPU)
                {
                    this.DrawCPUOrRenderingPane(this.m_GPUHierarchyGUI, this.m_GPUDetailHierarchyGUI, this.m_ViewSplit);
                }
                else
                {
                    this.DrawPane(this.m_CurrentArea);
                }
                GUILayout.EndVertical();
                SplitterGUILayout.EndVerticalSplit();
            }
        }

        private void OnLostFocus()
        {
        }

        private string PickFrameLabel()
        {
            if (this.m_CurrentFrame == -1)
            {
                return "Current";
            }
            return ((this.m_CurrentFrame + 1) + " / " + (ProfilerDriver.lastFrameIndex + 1));
        }

        private void PrevFrame()
        {
            int previousFrameIndex = ProfilerDriver.GetPreviousFrameIndex(this.m_CurrentFrame);
            if (previousFrameIndex != -1)
            {
                this.SetCurrentFrame(previousFrameIndex);
            }
        }

        private static string[] ProfilerColumnNames(ProfilerColumn[] columns)
        {
            string[] names = Enum.GetNames(typeof(ProfilerColumn));
            string[] strArray2 = new string[columns.Length];
            for (int i = 0; i < columns.Length; i++)
            {
                strArray2[i] = EditorGUIUtility.TextContent("ProfilerColumn." + names[(int) columns[i]]).text;
            }
            return strArray2;
        }

        private static void RepaintAllProfilerWindows()
        {
            IEnumerator enumerator = m_ProfilerWindows.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    ProfilerWindow current = (ProfilerWindow) enumerator.Current;
                    if (ProfilerDriver.lastFrameIndex != current.m_LastFrameFromTick)
                    {
                        current.m_LastFrameFromTick = ProfilerDriver.lastFrameIndex;
                        current.RepaintImmediately();
                    }
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable == null)
                {
                }
                disposable.Dispose();
            }
        }

        private void SelectProfilerClick(object userData, string[] options, int selected)
        {
            int num = this.m_ConnectionGuids[selected];
            ProfilerDriver.connectedProfiler = num;
        }

        private void SetCurrentFrame(int frame)
        {
            if ((((frame != -1) && Profiler.enabled) && (!ProfilerDriver.profileEditor && (this.m_CurrentFrame != frame))) && EditorApplication.isPlayingOrWillChangePlaymode)
            {
                EditorApplication.isPaused = true;
            }
            this.SetCurrentFrameDontPause(frame);
        }

        private void SetCurrentFrameDontPause(int frame)
        {
            this.m_CurrentFrame = frame;
        }

        private static void SetProfileDeepScripts(bool deep)
        {
            if (ProfilerDriver.deepProfiling != deep)
            {
                bool flag2 = true;
                if (EditorApplication.isPlaying)
                {
                    if (deep)
                    {
                        flag2 = EditorUtility.DisplayDialog("Enable deep script profiling", "Enabling deep profiling requires reloading scripts.", "Reload", "Cancel");
                    }
                    else
                    {
                        flag2 = EditorUtility.DisplayDialog("Disable deep script profiling", "Disabling deep profiling requires reloading all scripts", "Reload", "Cancel");
                    }
                }
                if (flag2)
                {
                    ProfilerDriver.deepProfiling = deep;
                    InternalEditorUtility.RequestScriptReload();
                }
            }
        }

        public void SetSelectedPropertyPath(string path)
        {
            if (ProfilerDriver.selectedPropertyPath != path)
            {
                ProfilerDriver.selectedPropertyPath = path;
                this.UpdateCharts();
            }
        }

        private static void ShowProfilerWindow()
        {
            EditorWindow.GetWindow<ProfilerWindow>(false);
        }

        void IProfilerWindowController.Repaint()
        {
            base.Repaint();
        }

        private static void UpdateChartGrid(float timeMax, ChartData data)
        {
            if (timeMax < 1500f)
            {
                float[] grid = new float[] { 1000f, 250f, 100f };
                string[] labels = new string[] { "1ms (1000FPS)", "0.25ms (4000FPS)", "0.1ms (10000FPS)" };
                data.SetGrid(grid, labels);
            }
            else if (timeMax < 10000f)
            {
                float[] singleArray2 = new float[] { 8333f, 4000f, 1000f };
                string[] textArray2 = new string[] { "8ms (120FPS)", "4ms (250FPS)", "1ms (1000FPS)" };
                data.SetGrid(singleArray2, textArray2);
            }
            else if (timeMax < 30000f)
            {
                float[] singleArray3 = new float[] { 16667f, 10000f, 5000f };
                string[] textArray3 = new string[] { "16ms (60FPS)", "10ms (100FPS)", "5ms (200FPS)" };
                data.SetGrid(singleArray3, textArray3);
            }
            else if (timeMax < 100000f)
            {
                float[] singleArray4 = new float[] { 66667f, 33333f, 16667f };
                string[] textArray4 = new string[] { "66ms (15FPS)", "33ms (30FPS)", "16ms (60FPS)" };
                data.SetGrid(singleArray4, textArray4);
            }
            else
            {
                float[] singleArray5 = new float[] { 500000f, 200000f, 66667f };
                string[] textArray5 = new string[] { "500ms (2FPS)", "200ms (5FPS)", "66ms (15FPS)" };
                data.SetGrid(singleArray5, textArray5);
            }
        }

        private void UpdateCharts()
        {
            int num = ProfilerDriver.maxHistoryLength - 1;
            int b = ProfilerDriver.lastFrameIndex - num;
            int firstSelectableFrame = Mathf.Max(ProfilerDriver.firstFrameIndex, b);
            foreach (ProfilerChart chart in this.m_Charts)
            {
                float[] scale = new float[chart.m_Series.Length];
                for (int i = 0; i < chart.m_Series.Length; i++)
                {
                    float num7;
                    float num8;
                    ProfilerDriver.GetStatisticsValues(ProfilerDriver.GetStatisticsIdentifier(chart.m_Series[i].identifierName), b, chart.m_DataScale, chart.m_Series[i].data, out num7);
                    if (chart.m_Type == Chart.ChartType.Line)
                    {
                        num8 = 1f / (num7 * (1.05f + (i * 0.05f)));
                    }
                    else
                    {
                        num8 = 1f / num7;
                    }
                    scale[i] = num8;
                }
                if (chart.m_Type == Chart.ChartType.Line)
                {
                    chart.m_Data.AssignScale(scale);
                }
                chart.m_Data.Assign(chart.m_Series, b, firstSelectableFrame);
            }
            bool flag = (ProfilerDriver.selectedPropertyPath != string.Empty) && (this.m_CurrentArea == ProfilerArea.CPU);
            ProfilerChart chart2 = this.m_Charts[0];
            if (flag)
            {
                chart2.m_Data.hasOverlay = true;
                foreach (ChartSeries series in chart2.m_Series)
                {
                    float num11;
                    int statisticsIdentifier = ProfilerDriver.GetStatisticsIdentifier("Selected" + series.identifierName);
                    series.CreateOverlayData();
                    ProfilerDriver.GetStatisticsValues(statisticsIdentifier, b, chart2.m_DataScale, series.overlayData, out num11);
                }
            }
            else
            {
                chart2.m_Data.hasOverlay = false;
            }
            for (ProfilerArea area = ProfilerArea.CPU; area <= ProfilerArea.GPU; area += 1)
            {
                ProfilerChart chart3 = this.m_Charts[(int) area];
                float num12 = 0f;
                float num13 = 0f;
                for (int j = 0; j < num; j++)
                {
                    float num15 = 0f;
                    for (int k = 0; k < chart3.m_Series.Length; k++)
                    {
                        if (chart3.m_Series[k].enabled)
                        {
                            num15 += chart3.m_Series[k].data[j];
                        }
                    }
                    if (num15 > num12)
                    {
                        num12 = num15;
                    }
                    if ((num15 > num13) && ((j + b) >= (firstSelectableFrame + 1)))
                    {
                        num13 = num15;
                    }
                }
                if (num13 != 0f)
                {
                    num12 = num13;
                }
                num12 = Math.Min(num12, this.m_ChartMaxClamp);
                if (this.m_ChartOldMax[(int) area] > 0f)
                {
                    num12 = Mathf.Lerp(this.m_ChartOldMax[(int) area], num12, 0.4f);
                }
                this.m_ChartOldMax[(int) area] = num12;
                float[] singleArray1 = new float[] { 1f / num12 };
                chart3.m_Data.AssignScale(singleArray1);
                UpdateChartGrid(num12, chart3.m_Data);
            }
            string str2 = null;
            if (ProfilerDriver.isGPUProfilerBuggyOnDriver)
            {
                str2 = "Graphics card driver returned invalid timing information. Please update to a newer version if available.";
            }
            else if (!ProfilerDriver.isGPUProfilerSupported)
            {
                str2 = "GPU profiling is not supported by the graphics card driver. Please update to a newer version if available.";
                if ((Application.platform == RuntimePlatform.OSXEditor) && !ProfilerDriver.isGPUProfilerSupportedByOS)
                {
                    str2 = "GPU profiling requires Mac OS X 10.7 (Lion) and a capable video card. GPU profiling is currently not supported on mobile.";
                }
            }
            this.m_Charts[1].m_Chart.m_NotSupportedWarning = str2;
        }

        internal class Styles
        {
            public GUIContent addArea = EditorGUIUtility.TextContent("Profiler.AddArea");
            public GUIStyle background = "OL Box";
            public GUIContent clearData = EditorGUIUtility.TextContent("Clear");
            public GUIContent currentFrame = EditorGUIUtility.TextContent("Profiler.CurrentFrame");
            public GUIContent currentProfiler = EditorGUIUtility.TextContent("Profiler.CurrentProfiler");
            public GUIContent deepProfile = EditorGUIUtility.TextContent("Profiler.DeepProfile");
            public GUIContent frame = EditorGUIUtility.TextContent("Frame: ");
            public GUIStyle header = "OL title";
            public GUIContent nextFrame = EditorGUIUtility.IconContent("Profiler.NextFrame");
            public GUIContent noData = EditorGUIUtility.TextContent("Profiler.NoFrameDataAvailable");
            public GUIContent noLicense = EditorGUIUtility.TextContent("Profiler.NoLicense");
            public GUIContent prevFrame = EditorGUIUtility.IconContent("Profiler.PrevFrame");
            public GUIContent profileEditor = EditorGUIUtility.TextContent("Profiler.ProfileEditor");
            public GUIStyle profilerGraphBackground = "ProfilerScrollviewBackground";
            public GUIContent profilerRecord = EditorGUIUtility.TextContent("Profiler.Record");

            public Styles()
            {
                this.profilerGraphBackground.overflow.left = -165;
            }
        }
    }
}

